package com.lizhaoshan.service.impl;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.lizhaoshan.pojo.Employee;
import com.lizhaoshan.pojo.User;
import com.lizhaoshan.service.TokenService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @program: reggie
 * @description:
 * @author: lamour
 * @create: 2022-05-15 19:01
 **/
@Service
public class TokenServiceImpl implements TokenService {
    @Override
    public String getToken(Employee employee) {
        Date start = new Date();
        //一小时有效时间
        long currentTime = System.currentTimeMillis() + 60 * 60 * 1000;
        Date end = new Date(currentTime);
        String token = "";

        token = JWT.create().withAudience(employee.getId()).withIssuedAt(start).withExpiresAt(end)
                .sign(Algorithm.HMAC256(employee.getPassword()));
        return token;
    }
}
